package com.psp.bu.persist.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.psp.bu.controller.res.enumModel.DemandCategoryEnum;
import com.psp.bu.model.DemandBean;
import com.psp.bu.persist.dao.DemandDao;

@Repository
public class DemandImpl extends BaseImpl implements DemandDao {

	protected static final String NAME_SPACE = NAME_SPACE_HEADER + ".DemandMapper";

	@Override
	public int selectCount(int cateCode, String content) {
		Map<String, Object> where = new HashMap<>();
		if(cateCode != 99) {
			DemandCategoryEnum e = DemandCategoryEnum.getCate(cateCode);
			where.put(e.getName(), e.getIndex());
		}
		where.put("content", content);
		return sqlSessionTemplate.selectOne(NAME_SPACE + ".selectCount", where);
	}

	@Override
	public List<DemandBean> selectList(int page, int pageSize, int cateCode, String content) {
		Map<String, Object> where = new HashMap<>();
		where.put("start", page * pageSize);
		where.put("length", pageSize);
		if(cateCode != 99) {
			DemandCategoryEnum e = DemandCategoryEnum.getCate(cateCode);
			where.put(e.getName(), e.getIndex());
		}
		where.put("content", content);
		return sqlSessionTemplate.selectList(NAME_SPACE + ".selectList", where);
	}

	@Override
	public int updateHandleState(String did, int state) {
		Map<String, Object> where = new HashMap<>();
		where.put("state",state);
		where.put("did", did);
		return sqlSessionTemplate.update(NAME_SPACE + ".updateHandleState", where);
	}

	@Override
	public DemandBean selectOneById(String did) {
		return sqlSessionTemplate.selectOne(NAME_SPACE + ".selectOneById", did);
	}


}
